<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>作用域</title>
</head>
<body>
    <script>
        let num = 1; 
        function fn(){
            console.log(num);
            num = 12;
            
            let sum = 10;
        }
        console.log(num)
        fn()
        //闭包 作用域链调用方法
        let nu = 10;
        function f1(){
            let nu = 100;
            function f2(){
                console.log('===>',nu)
            }
            f2()
        }
        f1()
        // 对象 取对象的两种方式 通过key值
        // console.log(obj.name);
        // console.log(obj['height']);
        // console.log(obj.say);
        let obj = {
            name:'didi',
            age:18,
            gender:'女',
            height:'170cm',
            say:function(){
                console.log('你好')
            }
        };
        
        for(let k in obj){
            console.log(k);
            console.log(obj[k])
            // console.log(obj)
        }

        let student1 = {
            name:'xixi',
            age:20,
            gender:'男',
            height:'180cm',
            hobby:'dance',
            action:function(){
                speak:chinese
                can:java
            }
        }
        let student2= {
            name:'lili',
            age:22,
            gender:'女',
            height:'160cm',
            hobby:'pingpong',
            action:function(){
                speak:English
                can:web
            }
        }
        for(k in student1){
            console.log(student1[k])
        }

        var obj2 = new Object();
        obj2.name = 'didi';
        obj2.age=18;
        obj2.say=function(){
            console.log('hi')
        }
        console.log(obj2)
        for(k in obj2){
            console.log(obj2[k])
        };

        //返回随机整数 
        function strar(min,max){
            return Math.random()*(max-min) + min;
        }
        let sum =  Math.floor(strar(10,15));
        while (true){
            let action = prompt('请输入10-15之内数字');
            console.log(sum)
            if(action > sum){
                alert('大了哦');
                console.log(action)
            }else if(action < sum){
                alert('猜小了');
                console.log(action)
            }else if(action == sum){
                alert('猜对啦！');
                console.log(action)
                break;
            }
        }
        // fn()
        function fn(){
            let action = prompt('请输入10-15之内数字');
            let sum =  Math.floor(strar(10,15));
            console.log(action);
            console.log(sum)
            if(action > sum){
                alert('大了哦');
            }else if(action < sum){
                alert('猜小了')
            }else if(action == sum){
                alert('猜对啦！');
            }else{
                let action = prompt('请输入10-15之内数字');
            }
       }
    </script>
</body>
</html>